import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class 寻找两个正序数组的中位数 {
    
    public static void main(String[] args) {

        int[] n1 = new int[]{};
        int[] n2 = new int[]{1};
        double result = findMedianSortedArrays(n1, n2);


        System.out.println("中位数:="+result);
        
    }

    private static double findMedianSortedArrays(int[] nums1, int[] nums2) {

        double result = 0.0D;

        if((null == nums1 || nums1.length < 1) && (null == nums2 || nums2.length < 1)) return result;

        List<Integer> sortedList = new ArrayList<>();

        sortedList.addAll(Arrays.stream(nums1).boxed().collect(Collectors.toList()));
        sortedList.addAll(Arrays.stream(nums2).boxed().collect(Collectors.toList()));


        Collections.sort(sortedList);

        if(sortedList.size() % 2 != 0){

            result = sortedList.get((sortedList.size()-1)/2);

        } else {

            int left = sortedList.get((sortedList.size()/2) -1);
            int right = sortedList.get((sortedList.size()/2));

            result = ( left + right ) / 2.0;

        }


        return result;
    }
}
